package com.jweb.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class WebUtil {
	// /** 用于登录成功后。强制刷新sessionid，防止session劫持 */
	// public static void sessionRefresh(HttpServletRequest request) {
	// request.getSession().invalidate();
	// }

	public static void setSessionAttribute(HttpServletRequest request, String name, Object value) {
		if (value != null) {
			request.getSession().setAttribute(name, value);
		} else {
			HttpSession session = request.getSession(false);
			if (session != null) {
				session.removeAttribute(name);
			}
		}
	}

	public static Object getSessionAttribute(HttpServletRequest request, String name) {
		HttpSession session = request.getSession(false);
		return (session != null ? session.getAttribute(name) : null);
	}

	public static String getSessionId(HttpServletRequest request) {
		HttpSession session = request.getSession(false);
		return (session != null ? session.getId() : null);
	}
}
